home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / documentstyle.cpp < prev    next >
C/C++ Source or Header  |  2004-10-21  |  5KB  |  159 lines

  1. /***************************************************************************
  2.                           documentstyle.cpp  -  description
  3.                              -------------------
  4.     begin                : Son Nov 10 2002
  5.     copyright            : (C) 2002 by Andre Simon
  6.     email                : andre.simon1@gmx.de
  7.  ***************************************************************************/
  8.  
  9. /***************************************************************************
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  ***************************************************************************/
  17.  
  18. #include "documentstyle.h"
  19.  
  20. namespace highlight {
  21.  
  22. DocumentStyle::DocumentStyle(const string &styleDefinitionFile)
  23. {
  24.   fileFound=load(styleDefinitionFile);
  25. }
  26. DocumentStyle::DocumentStyle():fileFound(false)
  27. {}
  28.  
  29. bool DocumentStyle::load(const string &styleDefinitionPath)
  30. {
  31.   ConfigurationReader styleConfig(styleDefinitionPath);
  32.   if (styleConfig.found()){
  33.     fontsize = styleConfig.getParameter("fontsize");
  34.     bgColour.setRGBValues(styleConfig.getParameter("bgcolour"));
  35.     defaultElem.set(styleConfig.getParameter("defaultcolour"));
  36.     comment.set(styleConfig.getParameter("comment"));
  37.     directive.set(styleConfig.getParameter("directive"));
  38.     str.set(styleConfig.getParameter("string"));
  39.     escapeChar.set(styleConfig.getParameter("escapechar"));
  40.     number.set(styleConfig.getParameter("number"));
  41.     dstr.set(styleConfig.getParameter("string_directive"));
  42.     line.set(styleConfig.getParameter("line"));
  43.  
  44.  
  45.     string tmpstr;
  46.   // TODO: Remove this check as soon as all themes have a brackets attribute
  47.     tmpstr=styleConfig.getParameter("symbol");
  48.     if (tmpstr.empty()) {
  49.       tmpstr=styleConfig.getParameter("defaultcolour");
  50.     }
  51.     symbol.set(tmpstr);
  52.  
  53. // TODO: Remove this check as soon as all themes have a sl-comment attribute
  54.     tmpstr=styleConfig.getParameter("sl-comment");
  55.     if (tmpstr.empty()) {
  56.       tmpstr=styleConfig.getParameter("comment");
  57.     }
  58.     slcomment.set(tmpstr);
  59.  
  60.     string paramVal;
  61.     vector<string> paramNames=styleConfig.getParameterNames();
  62.  
  63.     //collect keyword classes, save corresponding style definition
  64.     for (unsigned int i=0;i<paramNames.size();i++){
  65.       paramVal=paramNames[i];
  66.       if (paramVal.find("kw_class") != string::npos){
  67.          keywordStyles.insert(make_pair(StringTools::getParantheseVal(paramVal),
  68.                               new ElementStyle(styleConfig.getParameter(paramVal))));
  69.       }
  70.     }
  71.  
  72.     fileFound = true;
  73.   }
  74.   else {
  75.     fileFound = false;
  76.   }
  77.   return fileFound;
  78. }
  79.  
  80. DocumentStyle::~DocumentStyle()
  81. {
  82.   for(KSIterator iter = keywordStyles.begin(); iter != keywordStyles.end(); iter++){
  83.     delete (*iter).second;  //remove ElementStyle*
  84.   }
  85. }
  86.  
  87. string& DocumentStyle::getFontSize()
  88.   {
  89.     return fontsize;
  90.   }
  91. StyleColour& DocumentStyle::getBgColour()
  92.   {
  93.     return bgColour;
  94.   }
  95. ElementStyle& DocumentStyle::getDefaultStyle()
  96.   {
  97.     return defaultElem;
  98.   }
  99. ElementStyle& DocumentStyle::getCommentStyle()
  100.   {
  101.     return comment;
  102.   }
  103. ElementStyle& DocumentStyle::getSingleLineCommentStyle()
  104.   {
  105.     return slcomment;
  106.   }
  107.  
  108.  
  109. ElementStyle& DocumentStyle::getStringStyle()
  110.   {
  111.     return str;
  112.   }
  113. ElementStyle& DocumentStyle::getDirectiveStringStyle()
  114.   {
  115.     return dstr;
  116.   }
  117. ElementStyle& DocumentStyle::getEscapeCharStyle()
  118.   {
  119.     return escapeChar;
  120.   }
  121. ElementStyle& DocumentStyle::getNumberStyle()
  122.   {
  123.     return number;
  124.   }
  125. ElementStyle& DocumentStyle::getDirectiveStyle()
  126.   {
  127.     return directive;
  128.   }
  129. ElementStyle& DocumentStyle::getLineStyle()
  130.   {
  131.     return line;
  132.   }
  133. ElementStyle& DocumentStyle::getSymbolStyle()
  134.   {
  135.     return symbol;
  136.   }
  137. bool DocumentStyle::found () const
  138.   {
  139.     return fileFound;
  140.   }
  141. ElementStyle& DocumentStyle::getKeywordStyle(const string &className){
  142.   if (!keywordStyles.count(className)) return defaultElem;
  143.   return *keywordStyles[className];
  144. }
  145.  
  146. vector <string> DocumentStyle::getClassNames(){
  147.   vector <string> kwClassNames;
  148.   for(KSIterator iter = keywordStyles.begin(); iter != keywordStyles.end(); iter++){
  149.     kwClassNames.push_back( (*iter).first);
  150.   }
  151.   return kwClassNames;
  152. }
  153.  
  154. KeywordStyles& DocumentStyle::getKeywordStyles(){
  155.   return keywordStyles;
  156. }
  157.  
  158. }
  159.